package com.lanou.pianke.search.service.impl;


import com.lanou.pianke.search.EntityRepository.AcommentRepository;
import com.lanou.pianke.search.entity.ArticleComment;
import com.lanou.pianke.search.service.ArticleCommentService;
import org.elasticsearch.index.query.QueryStringQueryBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

@Service
public class ArticleCommentServiceImpl implements ArticleCommentService {

    @Autowired
    private AcommentRepository acommentRepository;

    @Override
    public List<ArticleComment> searchByAcommentContent(String searchContent) {
        QueryStringQueryBuilder builder = new QueryStringQueryBuilder(searchContent);
        System.out.println("查询语句: " + builder);
        Iterable<ArticleComment> searchResult = acommentRepository.search(builder);
        Iterator<ArticleComment> iterator = searchResult.iterator();
        List<ArticleComment> list = new ArrayList<>();
        while (iterator.hasNext()){
            list.add(iterator.next());
        }
        return list;
    }

    @Override
    public ArticleComment findByAcomid(String acomid) {
        return acommentRepository.findByAcomid(acomid);
    }


}
